﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using TrainingReminderSystem.Model;

namespace TrainingReminderSystem.Dal
{
    /// <summary>
    /// EFCore
    /// </summary>
    public partial class DbEntities : DbContext
    {
        #region 数据库表

        //public DbSet<SysPrintTemplate> SysPrintTemplate{ get; set; }

        //public DbSet<SysBasePrintTemplateVariable> SysBasePrintTemplateVariable{ get; set; }

        #endregion

        #region 视图

        //public DbSet<VProject> VProject { get; set; }

        #endregion

        protected void OnModelCreatingPartial(ModelBuilder builder)
        {
            #region 自定义函数

            //builder.HasDbFunction(() => DbFun.ScalarFunction(null));
            //builder.HasDbFunction(() => DbFun.ScalarFunction(null)).HasName("ScalarFunction").HasSchema("dbo");
            //builder.HasDbFunction(typeof(DbFun).GetMethod("ScalarFunction", BindingFlags.Static | BindingFlags.Public), options => { options.HasName("UdfFunction"); options.HasSchema("dbo"); });

            #endregion

            #region 数据库关系

            //EF6原版写法
            //modelBuilder.Entity<QB_CustomerInfo>()
            //    .HasMany(e => e.QB_CustomerCoupon)
            //    .WithRequired(e => e.QB_CustomerInfo)
            //    .HasForeignKey(e => e.CustomerID)
            //    .WillCascadeOnDelete(false);

            //builder.Entity<Wx_Inf_BranchShopPlatform_Relation>()
            //    .HasMany(m => m.Wx_Inf_ComponentVerifyTicketAccessToken).WithOne(m => m.Wx_Inf_BranchShopPlatform_Relation)
            //    .HasForeignKey(m => m.sAppID);

            #endregion

            #region decimal精度

            //builder.Entity<Wx_Inf_MerchantPlatform_Relation>().Property(p => p.Longitude).HasPrecision(18, 8);

            #endregion

            #region EF并发标记

            ////或者属性上加特效[Timestamp] 属性是byte[]类型
            //builder.Entity<TblTest>().Property(o => o.RowVersion).IsRowVersion();

            #endregion
        }
    }
}
